package com.example.springmvcdemo5;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author Q
 * @create 2025-05-28-9:39
 */
@RequestMapping("/book")
@RestController
public class BookController {
    @RequestMapping("/getList")
    public List<BookInfo> getList() {
        List<BookInfo> books = mockData();
        for(BookInfo bookInfo:books) {
            if(bookInfo.getStatus() == 1) {
                bookInfo.setStatusCN("可借阅");
            }else {
                bookInfo.setStatusCN("不可借阅");
            }
        }
        return books;
    }
    public List<BookInfo> mockData() {
        List<BookInfo> books = new ArrayList<>();
        for(int i = 0;i <= 15;i++) {
            BookInfo book = new BookInfo();
            book.setBookId(i);
            book.setBookName("书籍" + i);
            book.setAuthor("作者" + i);
            book.setNum(i * 5 + 3);
            book.setPrice(new BigDecimal(new Random().nextInt(100)));
            book.setPublishName("出版社" + i);
            book.setStatus(1);
            books.add(book);
        }
        return books;
    }
}
